import { createApp } from 'vue';
import ArcoVue from '@arco-design/web-vue';
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import globalComponents from '@/components';
import router from './router';
import store from './store';
import i18n from './locale';
import directive from './directive';
import './mock';
import App from './App.vue';
import confirmModal from '@/components/confirmModal';

/**
 * wujie相关代码
 */
import '@/utils/wujie';

// Styles are imported via arco-plugin. See config/plugin/arcoStyleImport.ts in the directory for details
// 样式通过 arco-plugin 插件导入。详见目录文件 config/plugin/arcoStyleImport.ts
// https://arco.design/docs/designlab/use-theme-package
import '@/assets/style/global.less';
import '@/api/interceptor';

const app = createApp(App);

app.use(ArcoVue, {});
app.use(ArcoVueIcon);
app.use(confirmModal);

app.use(store);
app.use(i18n);
app.use(globalComponents);
app.use(directive);

if (window.__POWERED_BY_WUJIE__) {
  let instance;
  window.__WUJIE_MOUNT = () => {
    instance = app;
    instance.use(router);
    instance.mount('#app');

    /**
     * 需要初始化
     */
    // window.$wujie?.bus.$on("")

    /**
     * token问题处理 ， 主应用和子应用共用同一个localstorage
     */

    /**
     * 主应用控制子应用的路由跳转
     */
    console.log('====================================');
    // console.log(window.__WUJIE);
    console.log('====================================');
    // window.__WUJIE.mount();
  };
  window.__WUJIE_UNMOUNT = () => {
    instance.unmount();
  };
} else {
  app.use(router);
  app.mount('#app');
}
